{  Statement: http://acmp.ru/?main=task&id_task=51
   Verdict: Accepted
}
uses
    SysUtils, Math;

var
    n,k,kk,ans,tt,i:longint;
    s:String;

begin
reset(input,'input.txt');
rewrite(output,'output.txt');
readln(S);
kk := pos(' ',s);
n := strtoint(copy(s,1,kk - 1));
delete(s,1,kk);
k := length(s);
if k >= n then write(n) else begin
    if n mod k = 0 then tt := k else tt := n mod k;
    ans := n;
    i := 1;
    while (n - i * k > tt) do begin
        ans := ans * (n - i * k);
        inc(i);
    end;
    if n mod k = 0 then ans := ans * k else ans := ans * (n mod k);
    write(ans);
end;
end.
